/* eslint-disable no-unused-vars */
import api from '@/api/index.js'

import  mockRequest from '@/api/mockAjax'//模拟请求
import { post, get, From, postJson } from '@/api/request'//真实请求
const state = {
    categoryList:[],//三级联动数组,存放在vuex方便其他页面使用
    bannerList:[],//轮播图数组
    floorList:[]
}

const mutations = {
    CATEGORYLIST(state, data) {
        state.categoryList = data
    },
    BANNERLIST(state,bannerlist){
      state.bannerList = bannerlist
    },
    FLOORLIST(state,floorlist){
      state.floorList = floorlist
    }
}

const actions = {
  async categoryList({commit}){
   let result = await get(api.reqCategoryList);
   if(result.code == 200){
     commit('CATEGORYLIST',result.data)
   }
  },
  getBannerList({commit}){
    return new Promise((resolve,reject)=>{
      mockRequest.get('/banner').then(res=>{
        commit('BANNERLIST',res.data)
        resolve(res.data)
      }).catch(err=>{
        reject(err)
      });
     
    })
  },
  getFloorList({commit}){
    return new Promise((resolve,reject)=>{
      mockRequest.get('/floor').then(res=>{
        commit('FLOORLIST',res.data)
        resolve(res.data)
      }).catch(err=>{
        reject(err)
      });
     
    })
  }
}

export default {
  state,
  mutations,
  actions
}
